<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <link rel="stylesheet" th:href="@{/static/element/index.css}"/>
    <style>
        .time {
            font-size: 13px;
            color: #999;
        }

        .bottom {
            margin-top: 13px;
            line-height: 12px;
        }

        .button {
            padding: 5px;
            float: right;
        }

        .image {
            width: 260px;
            height:300px;
            display: block;
        }

        .clearfix:before,
        .clearfix:after {
            display: table;
            content: "";
        }

        .clearfix:after {
            clear: both
        }
    </style>
</head>
<body>
<div id="app">
    <template>
        <el-row style="margin-top: 1%">
            <el-col :span="1.5">
            </el-col>
        </el-row>

        <div style="width:100%;height:100%;display: flex;align-items: center;flex-wrap: wrap;margin-top: 20px">
            <el-card :body-style="{ padding: '0px' }" v-for="(item,key) in tableData" :key="key">
                <img :src="item.picture" class="image">
                <div style="padding: 14px;">
                    <span>{{item.productName }}</span><br/>
                    <span>价格：{{item.price }}</span><br/>
                    <el-button type="danger" class="button" @click="addShop(item)" size="mini" style="">加入购物车</el-button>
                </div>
            </el-card>
        </div>
    </template>
</div>
</body>
<script th:src="@{/static/js/axios.min.js}"></script>
<script th:src="@{/static/js/request.js}"></script>
<script th:src="@{/static/js/common.js}"></script>
<script th:src="@{/static/api/admin/sysShopCar.js}"></script>
<script th:src="@{/static/js/vue.min.js}"></script>
<script th:src="@{/static/element/index.js}"></script>
<script th:src="@{/static/js/jquery.min.js}"></script>
<script th:src="@{/static/layer/layer.js}"></script>
<script>
    let id = getQueryString("id");
    new Vue({
        el: '#app',
        data() {
            return {
                currentPage: 1,
                pageSize: 10,
                total: 0,
                tableData: [],
                multipleSelection: [],
                button: {
                    add: false,
                    update: false,
                    delete: false
                },
                loading: false,
                queryForm: {
                    roleName: ''
                }
            }
        },
        created() {
            detail(id).then((res) => {
                if (res.code === '200') {
                    this.formData = res.data
                }
            });
            this.handleQuery();
            let sysButtons = JSON.parse(localStorage.getItem("mars-sysButtons"));
            this.button.add = sysButtons.indexOf("admin/sysShopCar/add") > -1;
            this.button.update = sysButtons.indexOf("admin/sysShopCar/update") > -1;
            this.button.delete = sysButtons.indexOf("admin/sysShopCar/delete") > -1;

        },
        methods: {
            handleChange(num,item){
                console.log(num);
                addOrUpdate2('/admin/sysShopCar/update',
                    {formData:{
                            ...item
                        }});
            },
            handExportData() {
                let queryParam = this.queryForm
                queryParam.pageNo = this.currentPage
                queryParam.pageSize = -1
                queryParam.id=id
                exports('/admin/sysShopCar/export', queryParam).then(res => {
                    this.$notify({
                        title: '成功',
                        message: '导出成功',
                        type: 'success'
                    });
                });
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            batchHandleDelete() {
                let params = {}
                if (this.multipleSelection.length === 0) {
                    this.$notify({
                        title: '失败',
                        message: '请选择删除行',
                        duration: 2000
                    });
                    return
                }
                deleteById('/admin/sysShopCar/delete/' + this.multipleSelection.map((item) => item.id), this);
            },
            switchChange(row) {
                this.formData = row
                update(this.formData).then(res => {
                    if (res.code === '200') {
                        this.$notify({
                            title: '成功',
                            message: '操作成功',
                            type: 'success'
                        });
                    }
                })
            },

            resetQuery() {
                this.queryForm = {}
                this.handleQuery()
            },


            handleCurrentChange(val) {
                this.currentPage = val;
                this.handleQuery();
            },
            handleSizeChange(val) {
                this.pageSize = val;
                this.handleQuery();
            },
            handleQuery() {
                let queryParam = this.queryForm
                queryParam.pageNo = this.currentPage
                queryParam.pageSize = this.pageSize
                this.loading = true
                pageList(queryParam).then((res) => {
                    if (res.code === '200') {
                        this.tableData = res.data.list;
                        this.total = res.data.count;
                        this.loading = false
                    } else {
                        this.loading = false;
                        this.$notify({
                            title: '失败',
                            message: res.message,
                            type: 'error'
                        });
                    }
                });
            },
            addShop(row) {
                addOrUpdate('/admin/sysShopCar/add', this);
            },

            handleAddOrUpdate(type, row) {
                if (type === 1) {
                    openPage('新增购物车', '/admin/sysShopCar/sysShopCarAddUpdate.html', this);
                } else {
                    openPage('修改购物车', '/admin/sysShopCar/sysShopCarAddUpdate.html?id=' + row.id, this);
                }
            },
        }
    });
</script>
</html>
